package leetcode.offer;

import java.util.HashMap;
import java.util.Map;

/**
 * ClassName: Offer56II_SingleNumber
 * Description: leetcode-剑指offer 56 - II 数组中数字出现的次数II
 * date: 2021-11-17 21:55
 *
 * @author liyifan
 */
public class Offer56II_SingleNumber {
    public int singleNumber(int[] nums) {
        HashMap<Integer, Integer> map = new HashMap<>();
        for (Integer x:
             nums) {
            map.put(x, map.getOrDefault(x, 0) + 1);
        }
        for (Map.Entry<Integer, Integer> entry:map.entrySet()) {
            if (entry.getValue() == 1) {
                return entry.getKey();
            }
        }
        return 0;
    }
}
